package hku.cs.lunuo.rank;

import java.util.ArrayList;
import java.util.List;

import org.jdom.Element;

public class DefaultLabel implements Label {
	List<Float> ties = new ArrayList<Float>();

	public DefaultLabel(float susc) {
		ties.add(susc);
	}
	
	public DefaultLabel(List<Float> ties) {
		this.ties = ties;
	}
	
	public DefaultLabel(List<Float> tl, float cc) {
		for(int i=0; i<tl.size(); i++){
			this.ties.add(tl.get(i));
		}
		this.ties.add(cc);
	}
	
	public DefaultLabel(float susc, float conf) {
		this.ties.add(susc);
		this.ties.add(conf);
	}
	
	public List<Float> getGene(){
		return this.ties;
	}

	@Override
	public String getLabelName() {
		return "DEFAULTLABEL";
	}
	
	public float getMainGene() {
		if(this.ties.size()>=1)
			return this.ties.get(0);
		else
			return 0;
	}
	
	public float getMinGene() {
		if(this.ties.size()>=1)
			return this.ties.get(this.ties.size()-1);
		else
			return 0;
	}
	
	public void setMinGene(float susc) {
		if(this.ties.size()>=1)
			this.ties.set(this.ties.size()-1, susc);
//		else
//			this.ties.add(susc);
	}
	
	public void copy(DefaultLabel dl) {
		if(getTiesLayer()>dl.getTiesLayer()) {
			for(int i=0; i<dl.getTiesLayer(); i++) {
				this.ties.set(i, dl.ties.get(i));
			}
		}else {
			throw new IllegalStateException("dl size must smaller");
		}
	}
	
	public int getTiesLayer() {
		return this.ties.size();
	}

	@Override
	public void toXML(Element xmlStmt) {
		Element sus = new Element("suspiciousness");
		String tmp = "";
		if(this.ties.size()>=1)
			tmp = String.valueOf(this.ties.get(0));
		for(int i = 1; i < this.ties.size(); i++) {
			tmp+=" ["+this.ties.get(i)+"]";
		}
		sus.setText(tmp);
		xmlStmt.addContent(sus);
	}

	@Override
	public int compareTo(Object o) {
		DefaultLabel dl = (DefaultLabel)o;
		int a = this.ties.size();
		int b = dl.ties.size();
		int c = a;
		if(a!=b)
			c = a>b?b:a;
		for(int i = 0; i < c; i++) {
			if(this.ties.get(i)>dl.ties.get(i))
				return 1;
			else if(this.ties.get(i)<dl.ties.get(i))
				return -1;
		}
		if(a==b)
			return 0;
		else
			return a>b?1:-1;
	}

}
